package org.example.hook;

import java.util.concurrent.locks.LockSupport;
import java.util.logging.Logger;

/**
 * 关机钩子
 *
 * @author bobo
 * @since 2024/4/26
 */
public class ShutdownHook implements Runnable {

	Logger logger = Logger.getLogger(ShutdownHook.class.getName());

	private final long powerOffTime;

	public ShutdownHook(long powerOffTime) {
		this.powerOffTime = powerOffTime;
	}

	@Override
	public void run() {
		LockSupport.parkUntil(System.currentTimeMillis() + powerOffTime * 1000);
		logger.info("shutdown");
	}
}
